
<style media="screen">
td{
    white-space: nowrap
}
</style>

<Widget:show bdcls="no-padding" col="12" title="公共字典表" >
    <Widget:action >
    <a class="btn btn-sm red" data-pjax href="{:U("Db/table?f=$f")}">返回</a>
    <a ajax-add-dialog href="{:U("Dic/add?f=$f")}" class="btn blue">新增字典</a>
    </Widget:action>
    <div class="table-scrollable">
        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th >字段名</th>
                <th >标签</th>
                <th >类型</th>
                <th >输入格式</th>
                <th >提示</th>
                <th >默认值</th>
                <th >自动完成</th>
                <th width="100">#</th>
            </tr>
            </thead>
            <tbody>
                <volist name="dics" id="tbs">
                <tr>
                    <td>{$tbs.field}</td>
                    <td><a href="#" editable-input data-name="label" data-type="text" data-pk="{$tbs.field}" >{$tbs.label}</a></td>
                    
                    <td><a href="#" editable-select-ipttype data-name="ipttype" data-type="select" data-value="{$tbs.ipttype}" data-pk="{$tbs.field}" ></a>
                    <in name="tbs[ipttype]" value="select">
                    &nbsp;
                        <a href="#" data-value="{$tbs.list}" data-name="list" editable-textarea data-type="textarea" data-pk="{$tbs.field}">
                        <Ui:icon name="list" />
                        </a>
                    </in>
                    </td>
                    <td><a href="#" editable-select-format data-name="format" data-type="select" data-value="{$tbs.format}" data-pk="{$tbs.field}" ></a></td>
                    <td><a href="#" editable-input data-name="tip" data-type="text" data-pk="{$tbs.field}" ></a></td>
                    
                    <td><a href="#" editable-input data-name="defvalue" data-type="text" data-pk="{$tbs.field}" >{$tbs.defvalue}</a></td>
                    <td><a href="#" editable-select-auto data-name="auto" data-type="select" data-value="{$tbs.auto}" data-pk="{$tbs.field}" >{$tbs.auto}</a></td>
                    
                    
                    <td>
                        
                        <a data-delete-ajax href="{:U("Dic/delete?tb=dic&f=$f&field=$tbs[field]")}"><i class="glyphicon glyphicon-remove"></i></a>
                    </td>
                </tr>
                </volist>
            </tbody>
        </table>
    </div>
</Widget:show>
<script type="text/javascript">
$(function(){

    $('[data-delete-ajax]').on('click',function(event){
        event.preventDefault();
        var url = $(this).attr('href');
        $.get(url,function(req){
            $.bootstrapGrowl(req.info, {
                type: 'danger',
                align: 'center',
            });
            $.pjax.reload('[pjax-content]');
        })
    })

    $('[ajax-add-dialog]').on('click',function(event){
        event.preventDefault();
        var box = $('<div style="max-height:500px;overflow-y: auto;" class="row"></div>');
        var size = $(this).attr('dialog-size');
        if (!size) size = 'size-wide';
        var url = $(this).attr('href');
        var title = $(this).attr('dialog-title');
        box.load(url);
        BootstrapDialog.show({
            message: box,
            size:size,
            title:title,
            buttons: [{
                label: '确定',
                action: function(dialogRef) {
                    var form = dialogRef.getModalBody().find('form');
                    if (form.length > 0) {
                        var url = form.attr('action');
                        var data = form.serialize();
                        $.post(url,data,function(req){
                            $.bootstrapGrowl(req.info);
                            if (req.status == 1) {
                                dialogRef.close();
                                $.pjax.reload('[pjax-content]');
                            }
                        })
                    }else{
                        dialogRef.close();
                    }
                }
            },{
                label: '取消',
                action: function(dialogRef){
                    dialogRef.close();
                }
            }]
        });
    })

    var url = "{:U("Dic/updateFrom?tb=dic&f=$f")}";
    $.fn.editable.defaults.url = url;

    $('[editable-input]').editable();
    $('[editable-select-ipttype]').editable({
        prepend: "请选择",
        source: [
            {value: 'input', text: 'input'},
            {value: 'password', text: 'password'},
            {value: 'select', text: 'select'},
            {value: 'number', text: 'number'},
            {value: 'date', text: 'date'},
            {value: 'time', text: 'time'},
            {value: 'dic', text: '字典'},
            {value: 'datetime', text: 'datetime'},
            {value: 'hidden', text: 'hidden'},
            {value: 'checkbox', text: 'checkbox'},
            {value: 'textarea', text: 'textarea'},
            {value: 'umeditor', text: 'umeditor'},
            {value: 'file', text: 'file'},
            {value: 'fileinput', text: 'fileinput'},
            {value: 'upimg', text: 'upimg'},
        ]
    });

    $('[editable-select-ipttype]').on('save', function(e, params) {
        $.pjax.reload('[pjax-content]');
    });

    $('[editable-select-format]').editable({
        prepend: "文本",
        source: [
            {value: 'text', text: '文本'},
            {value: 'number', text: '数字'},
            {value: 'email', text: '邮箱'},
            {value: 'url', text: '网址'},
            {value: 'date', text: '日期'},
            {value: 'time', text: '时间'},
            {value: 'datetime', text: '日期+时间'},
        ]
    });

    $('[editable-select-auto]').editable({
        prepend: "请选择",
        source: [
            {value: '', text: '不处理'},
            {value: 'toDate', text: 'toDate'},
            {value: 'toDatetime', text: 'toDatetime'},
            {value: 'strtotime', text: 'strtotime'},
            {value: 'cut', text: 'cut'},
            {value: 'url', text: 'url'},
            {value: 'link', text: 'link'},
        ]
    });

    $('[editable-select-isshow]').editable({
        prepend: "隐藏",
        source: [
            {value: '1', text: '显示'},
            {value: '0', text: '隐藏'},
        ]
    });

    $('[editable-select-valid]').editable({
        prepend: "选填",
        source: [
            {value: 'required', text: '必填'},
            {value: '', text: '选填'},
        ]
    });


    $('[data-editable]').editable();

    $('[editable-textarea]').editable({
        placement:"bottom",
        display: function(value, sourceData) {
            $(this).html('<i class="glyphicon glyphicon-th-list "></i>');
        }
    });

    $('select[name=tb]').on('change',function(){
        var tb = $(this).val();
        var container = $('[pjax-content]');
        var url = window.location.href;
        url = U('tb',tb,url);
        $.pjax({url: url, container: container})
    })

    
})
</script>
